package com.open.capacity.user.controller;

import com.github.pagehelper.PageInfo;
import com.open.capacity.common.model.SysRole;
import com.open.capacity.common.model.SysUser;
import com.open.capacity.common.util.PageUtil;
import com.open.capacity.common.web.PageResult;
import com.open.capacity.common.web.Result;
import com.open.capacity.user.service.EducationalAdminService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author cheng
 * @date 2021-02-02 11:09
 */
@Slf4j
@Api(tags = "EducationalAdim API")
@RestController
public class EducationalAdminController {
    @Autowired
    private EducationalAdminService educationalAdminService;

    @ApiOperation(value = "教务人员查询用户")
    @GetMapping("/persons")
    public PageResult<SysUser> findPersons(@RequestParam Map<String, Object> params){
        PageUtil.pagePreProcess(params);
        List<SysUser> list= educationalAdminService.findPersons(params);
        PageInfo<SysUser> pageInfo = new PageInfo<>(list);
//        int count=educationalAdminService.findPersonsCount(params);
        return PageResult .<SysUser>builder().count(pageInfo.getTotal()).data(pageInfo.getList()).code(0).build();
    }
    @ApiOperation(value = "教务人员查询用户")
    @GetMapping("/personList")
    public PageResult<SysUser> findPersonList(@RequestParam Map<String, Object> params){
        return educationalAdminService.findPersonList(params);
    }

    @ApiOperation(value = "添加用户时查询非学生角色")
    @GetMapping("/rolesNoStudent")
    public PageResult<SysRole> findRolesNoStudent(@RequestParam Map<String, Object> params){
        List<SysRole> list= educationalAdminService.findRolesNoStudent(params);
        return PageResult .<SysRole>builder().count((long) list.size()).data(list).code(0).build();
    }

    @ApiOperation(value = "查询班主任")
    @GetMapping("/teachers")
    public PageResult<SysUser> findTeacher(@RequestParam Map<String, Object> params){
        List<SysUser> list= educationalAdminService.findTeacher(params);
        return PageResult .<SysUser>builder().count((long) list.size()).data(list).code(0).build();
    }

    @ApiOperation(value = "添加学生或修改学生")
    @PostMapping("/teachers/addStudent")
    public Result addStudent(@RequestBody SysUser sysUser){
        return educationalAdminService.addStudent(sysUser);
    }
}
